package com.etc

import org.apache.spark.SparkConf
import org.apache.spark.streaming.{Seconds, StreamingContext}

/**
  * @Auther: Wangcc
  * @Date: 2018/8/27 16:36
  * @Description: wordcount scala
  */
object WordCountScala {

  def main(args: Array[String]): Unit = {
    val con = new SparkConf().setAppName("WordCountScala").setMaster("local")
    val javasf = new StreamingContext(con,Seconds(1))
    val lines = javasf.socketTextStream("localhost",9999)
    val wordrdd = lines.flatMap(lines => lines.split(" "))
    val parmap = wordrdd.map( words => (words,1))
    val wordCounts = parmap.reduceByKey(_+_)
    Thread.sleep(5000)
    wordCounts.print()

    javasf.start()
    javasf.awaitTermination()
  }

}
